import 'package:flutter/material.dart';

extension ColorHexEx on String {
  Color toHexColor({double opacity = 1.0}) {
    assert(RegExp(r'^#([0-9a-fA-F]{6})|([0-9a-fA-F]{8})$').hasMatch(this), 'hex color must be #rrggbb or #rrggbbaa');
    return Color(int.parse(substring(1), radix: 16) + (length == 7 ? (opacity * 255).toInt() << 24 : 0x00000000));
  }
}
